home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / Peon / PeonSDK-Win32-1.0.0.exe / {app} / PeonMain / source / IniConfigReader.cpp < prev    next >
C/C++ Source or Header  |  2005-08-18  |  2KB  |  104 lines

  1. /*
  2. WGT - Win32 Games Programming Library
  3. Copyright (C) 2002-2004 Erik Yuzwa
  4.  
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9.  
  10. This library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. Library General Public License for more details.
  14.  
  15. You should have received a copy of the GNU Library General Public
  16. License along with this library; if not, write to the Free
  17. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  
  19. Erik Yuzwa
  20. wazoo AT wazooenterprises DOT com
  21. */
  22.  
  23. #include "IniConfigReader.h"
  24.  
  25. namespace peon
  26. {
  27.  
  28.     IniConfigReader::IniConfigReader(const String& strFile)
  29.     {
  30.         //TCHAR strOutput[MAX_PATH];
  31.         //sprintf(strOutput, "attempting to load ini: %s\n", strFile.c_str());
  32.         //OutputDebugString(strOutput);
  33.         m_strFileName = strFile;
  34.     
  35.     }
  36.  
  37.     IniConfigReader::~IniConfigReader()
  38.     {
  39.  
  40.     }
  41.  
  42.     DWORD IniConfigReader::getString(const String strSection, const String strKey, const String strDefault, String& strReturn)
  43.     {
  44.  
  45.         DWORD dwResult = 0;
  46.         TCHAR strTemp[MAX_PATH];
  47.         ZeroMemory( &strTemp, sizeof( strTemp ) );
  48.         dwResult = GetPrivateProfileString(strSection.c_str(),
  49.                                         strKey.c_str(),
  50.                                         strDefault.c_str(),
  51.                                         strTemp,
  52.                                         MAX_PATH,
  53.                                         m_strFileName.c_str());
  54.  
  55.         strReturn = strTemp;
  56.  
  57.         
  58.         return dwResult;
  59.     }
  60.     
  61.     UINT IniConfigReader::getInt(String strSectionName, String strKeyName, int iDefault)
  62.     {
  63.  
  64.         UINT iResult;
  65.  
  66.         iResult = GetPrivateProfileInt(strSectionName.c_str(),
  67.                                     strKeyName.c_str(),
  68.                                     iDefault,
  69.                                     m_strFileName.c_str());
  70.         return iResult;
  71.     }
  72.  
  73.     bool IniConfigReader::getBool(const String strSection, const String strKey, const String strDefault)
  74.     {
  75.  
  76.         String strTemp = "";
  77.  
  78.         getString(strSection, strKey, strDefault, strTemp);
  79.  
  80.         if(strTemp == "TRUE")
  81.         {
  82.             return true;
  83.         }else
  84.         {
  85.             return false;
  86.         }
  87.  
  88.     }
  89.  
  90.     float IniConfigReader::getFloat(String strSection, String strKey, String strDefault)
  91.     {
  92.  
  93.         String strTemp;
  94.  
  95.         getString(strSection, strKey, strDefault, strTemp);
  96.  
  97.         return (float)strtod(strTemp.c_str(),TEXT('\0'));
  98.         
  99.  
  100.     }
  101.  
  102.  
  103. }
  104.